﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using EnvironmentalMonitor.Support.Business.Environmental;
using EnvironmentalMonitor.Support.Business;
using EnvironmentalMonitor.Support.Module;
using EnvironmentalMonitor.Support.Resource;

namespace EnvironmentalMonitor.WebApplication.Environmental.Machine
{
    /// <summary>
    /// 保存Json数据页面类
    /// </summary>
    public partial class SaveJson : EnvironmentalMonitor.WebApplication.Abstract.AbstractSaveJson
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            const string GUID = "guid";
            const string REMARK = "remark";

            const string ROOM_ID = "roomid";
            const string NAME = "name";

            EnvironmentalMonitor.Support.Module.Manage.User sessionUser = this.Session[Constant.SESSION_KEY_USER] as EnvironmentalMonitor.Support.Module.Manage.User;
            DateTime now = DateTime.Now;

            EnvironmentalMonitor.Support.Module.Environmental.Machine module = new Support.Module.Environmental.Machine();
            module.Guid = this.ParameterString(GUID);
            module.InsertUserId = sessionUser.Guid;
            module.InsertTime = now;
            module.UpdateUserId = sessionUser.Guid;
            module.UpdateTime = now;
            module.Remark = this.ParameterString(REMARK);
            module.Validity = true;

            module.RoomId = this.ParameterString(ROOM_ID);
            module.Name = this.ParameterString(NAME);

            this.SaveJsonData = new Abstract.SaveJsonData();
            MachineBusiness business = new MachineBusiness();
            if (string.IsNullOrEmpty(module.Guid))
            {
                this.SaveJsonData.success = business.Insert(module);
            }
            else
            {
                this.SaveJsonData.success = business.Update(module);
            }
            if (!this.SaveJsonData.success)
            {
                this.SaveJsonData.msg = "数据操作失败！";
            }

            string json = this.Json();

            this.Response.Write(json);
            this.Response.Flush();
            this.Response.End();
        }
    }
}